// GPEncryptDlg.h : header file
//

#pragma once
#include "afxcmn.h"
#include <locale.h>
#include <map>
#include "gpgme/gpgme.h"

#include "afxwin.h"

using std::map;

enum GPGME_KEY_TYPE
{
	ICON_KEYPAIR = 0,
	ICON_PUBKEY  = 1,
	ICON_EXP_KEYPAIR = 2,
	ICON_EXP_PUBKEY  = 3,
	ICON_DISABLE_KEYPAIR = 4,
	ICON_DISABLE_PUBKEY  = 5
};

// CGPEncryptDlg dialog
class CGPEncryptDlg : public CDialog
{
// Construction
public:
	CGPEncryptDlg(CWnd* pParent = NULL);	// standard constructor
	~CGPEncryptDlg();
// Dialog Data
	enum { IDD = IDD_GPENCRYPT_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

public:
	CImageList m_key_icon;
	CListCtrl m_list_all_keys;
	CListCtrl m_list_used_keys;
	CButton m_check_text_output;

	afx_msg void OnNMDblclkListAllVaildKeys(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMDblclkListUsedKeys(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedButtonOk();
	afx_msg void OnBnClickedCheckTextOutput();
	afx_msg void OnBnClickedButtonCancel();
	afx_msg LRESULT OnProgressDlgCancel(WPARAM wparam, LPARAM lparam);

public:
	gpgme_ctx_t              ctx;
	map<CString,gpgme_key_t> m_keys;
	map<CString,bool> m_keys_is_secret;
	HANDLE hTerminalProcess;

	void InitGPGMESystem(gpgme_protocol_t proto);
	void GetKeysInfoToListctrl();
	void GetPrivateKeysList();
	void GenerateKeyStatus(gpgme_key_t key, CString& stringTmp);
	void GenerateUserInfoString(gpgme_key_t key, CString& stringTmp);
	void GenerateSubkeysInfoString(gpgme_subkey_t subkeys, CString& subkeys_info);
	void MoveListItem(CListCtrl& list_dst,CListCtrl& list_src);
	GPGME_KEY_TYPE DetermineKeyType(gpgme_key_t key);
};
